home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ivbsrc / winend.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  2.2 KB  |  73 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Exit Windows"
  4.    ClientHeight    =   4020
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   7365
  8.    Height          =   4425
  9.    Icon            =   WINEND.FRX:0000
  10.    Left            =   1035
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   4020
  14.    ScaleWidth      =   7365
  15.    Top             =   1140
  16.    Width           =   7485
  17. Declare Function ExitWindows Lib "User" (ByVal dwReserved As Long, ByVal wReturnCode As Integer) As Integer
  18. 'Return to DOS
  19. Const EW_EXITWINDOWS = &H0
  20. 'Reboot computer
  21. Const EW_REBOOTSYSTEM = &H43
  22. 'Exit to DOS & restart Windows
  23. Const EW_RESTARTWINDOWS = &H42
  24. 'Keep track of why Resize event
  25. 'is being triggered.
  26. Dim State%
  27. 'We set the EW_CURRENTEXITTYPE constant
  28. 'to the type of exit we want for this
  29. 'demonstration program.
  30. Const EW_CURRENTEXITTYPE = EW_EXITWINDOWS
  31. Sub Form_Click ()
  32.   State% = 3             'Mark that program is in Click event
  33.   Form1.WindowState = 1  'Minimize WinEnd
  34.   X% = ExitWindows(EW_CURRENTEXITTYPE, 0)
  35.   If X% = 0 Then
  36.     MsgBox "Windows Reboot aborted by an application.", 16, "Message from WinEnd"
  37.     'Reset program since it was aborted
  38.     State% = 2
  39.   End If
  40. End Sub
  41. Sub Form_Load ()
  42.   State% = 1
  43.   Form1.WindowState = 1 'Minimize the form
  44. End Sub
  45. Sub Form_Resize ()
  46. ' The Form_Resize event procedure
  47. ' uses the form level variable State%
  48. ' to let it react to resize events
  49. ' based on the point at which the
  50. ' resize event occurs.
  51. 'State%'s          Purpose
  52. ' Value
  53. '  1      Used to ignore initial
  54. '         resize event when program
  55. '         launched.
  56. '  2      Used to activate Form_Click
  57. '         event when you want to exit
  58. '         windows. WinEnd resets
  59. '         State% to 2 if the exit
  60. '         fails (for whatever
  61. '         reason).
  62. '  3      Used while trying to shut
  63. '         down Windows to avoid
  64. '         displaying the WinEnd form.
  65.   Select Case State%
  66.     Case 1        'After FORM_LOAD
  67.       State% = 2
  68.     Case 2        'After activated
  69.       Call Form_Click
  70.     Case 3        'During FORM_CLICK
  71.   End Select
  72. End Sub
  73.